/*
 * @Author: fankewen 835656320@qq.com
 * @Date: 2023-12-14 14:01:54
 * @LastEditors: fankewen 835656320@qq.com
 * @LastEditTime: 2023-12-18 11:52:05
 * @FilePath: \vue\src\utils\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios';
import { Message } from 'element-ui';
const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    baseURL: '/api',
    timeout: 5000
});

service.interceptors.request.use(
    config => {
        // config.headers.Authorization = "Token"; // 例如，添加认证头
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject(error);
    }
);

service.interceptors.response.use(
    response => {
        console.log(30, response);
        // if (!response.data.succeeded) {
        //     Message.error(`${response.data.error_message}`)
        // }
        if (response.status === 200) {
            return response.data;
        }
        else {
            Promise.reject();
        }
    },
    error => {
        console.log(42,error);
        switch (error.response.status) {
            case 500:
                error.message = '服务器内部错误'
                break
            case 400:
                error.message = '请求错误'
                break
            case 401:
                error.message = '未授权请求'
                break
            case 404:
                error.message = '请求地址错位'
                break
        }
        Message.error(`${error.message}`)
        return Promise.reject(error);
    }
);

export default service;
